package 复习.博客2.哈希;

public class 缺失的第一个正整数 {
    public int minNumberDisappeared (int[] nums) {
        // write code here
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] <= 0) nums[i] = nums.length + 1;
        }

        for (int i = 0; i < nums.length; i++) {
            if(Math.abs(nums[i]) < nums.length + 1){
                nums[Math.abs(nums[i]) - 1] = -Math.abs(nums[Math.abs(nums[i]) - 1]);
            }
        }

        for (int i = 0; i < nums.length; i++) {
            if(nums[i] > 0){
                return i + 1;
            }
        }
        return nums.length + 1;
    }
}

/*
public int minNumberDisappeared (int[] nums) {
        // write code here
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] <= 0) nums[i] = nums.length + 1;
        }

        for (int i = 0; i < nums.length; i++) {
            if(Math.abs(nums[i]) < nums.length + 1){
                nums[Math.abs(nums[i]) - 1] = -Math.abs(nums[Math.abs(nums[i]) - 1]);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] > 0){
                return i + 1;
            }
        }
        return nums.length + 1;
    }
 */